﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
namespace IntroduceCompany.Controllers
{
    public class PercentageBarController : Controller
    {
        public ActionResult Show(string percent)
        {
            //dimension of outside rectangel
            int height = 14;
            int width = 200;

            //dimension of inside rectangel(percent bar)
            float per = float.Parse(percent);
            float perheight = height - 1;
            float perwidth = (per * width) / 100;

            using (var bmpOut = new Bitmap(width+1, height+1))// frame to draw
            {
                var g = Graphics.FromImage(bmpOut);

                var gradientBrush = new SolidBrush(Color.DeepSkyBlue);
                Pen pen = new Pen(Color.Blue, 1);

                g.DrawRectangle(pen, 0, 0, width, height);
                g.FillRectangle(gradientBrush, 1, 1, perwidth, perheight);
                
                var ms = new MemoryStream();
                bmpOut.Save(ms, ImageFormat.Png);
                var bmpBytes = ms.GetBuffer();
                bmpOut.Dispose();
                ms.Close();

                return new FileContentResult(bmpBytes, "image/png");
            }
        }
    }
}
